using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing ;
using System.Windows.Forms;

namespace PrintDialogProject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            PrintDocument prdoc = new PrintDocument();
            prdoc.PrintPage += new PrintPageEventHandler(document_PrintPage);
            printDialog1.ShowNetwork = true;
            printDialog1.Document=prdoc;
            printDialog1.PrinterSettings.PrinterName = "HP LaserJet 4050 Series PS";
            DialogResult result = printDialog1.ShowDialog();           
            if (result == DialogResult.OK)
            {
                prdoc.PrinterSettings = printDialog1.PrinterSettings;
                prdoc.Print();
            }

        }
        private void document_PrintPage(
            object sender,
                PrintPageEventArgs e)
        {
            string text = richTextBox1.Text;
            Font printFont =
                new Font("Arial", 35,
                FontStyle.Regular);

            e.Graphics.DrawString(text, printFont,
                Brushes.Black, 0, 0);

        }
        private void button2_Click(object sender, EventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            PrintDocument prdoc = new PrintDocument();
            prdoc.PrintPage += new PrintPageEventHandler(document_PrintPage);
            pd.ShowNetwork = true;
            pd.Document = prdoc;
            pd.PrinterSettings.PrinterName = "HP LaserJet 4050 Series PS";
            DialogResult result = pd.ShowDialog();
            if (result == DialogResult.OK)
            {
                prdoc.PrinterSettings = pd.PrinterSettings;
                prdoc.Print();
            }
            
        }
    }
}